package com.tgy.crud.controller;

import com.tgy.crud.common.CommonResult;
import com.tgy.crud.domain.Person;
import com.tgy.crud.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/person")
public class PersonController {

    @Autowired
    private PersonService personService;

    @GetMapping("/{id}")
    public Person findPerson(@PathVariable("id")Integer id){

        Person person = personService.findPersonById(id);

        return person;
    }

    @GetMapping("/update")
    public CommonResult update(Person person){

        int updateNum = personService.updatePerson(person);

        return CommonResult.success(null);
    }

}
